﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LX.Core.Utils;

namespace LX.Core.Validation
{
    public abstract class ValidExpression<TEntity> : IValidExpression<TEntity>
    {
        public  ValidationResult Valid(TEntity entity)
        {
            var result = new ValidationResult();
            ValidEntity(result,entity);
            return result;
        }

        public abstract void ValidEntity(ValidationResult result,TEntity entity);

        protected void PushError(ValidationResult result,String errmsg)
        {
            result.Errors.Add(errmsg);
        }

        protected void NoEmpty(ValidationResult result, String name, String value)
        {
            if (Helper.StringIsEmpty(value))
            {
                PushError(result,name + "为必填项");
            }
        }
    }
}
